<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form"  :inline="true" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="姓名">
              <el-input v-model="params.realname" placeholder="请输入用户姓名" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="手机号">
              <el-input v-model="params.username" placeholder="请输入用户手机号" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-button style="margin-left:60px" type="primary" @click="search()">查询</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- table -->
    <div class="table" v-loading="tableLoading">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column
          type="index"
          label="序号"
          fixed="left"
          align="center"
          :index="table_index"
          width="50"
        />
        <el-table-column prop="realname" align="center" label="姓名" />
        <el-table-column prop="username" align="center" label="电话" >
            <template slot-scope="scope">
              {{scope.row.username | phonereg}}
            </template>
        </el-table-column>
        <el-table-column prop="amount" align="center" label="奖励金额" />
        <el-table-column prop="freezeRemark" align="center" label="备注" />
        <el-table-column prop="name" align="center" label="冻结状态">
          <template slot-scope="scope">
            <span v-if="scope.row.freeze==1">未冻结</span>
            <span v-if="scope.row.freeze==2">冻结</span>
          </template>
        </el-table-column>
        <el-table-column prop="freezeTime" align="center" label="冻结时间" />
        <el-table-column prop="transTime" align="center" label="交易操作时间" />
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <div>
              <el-button type="text" @click="jumufn(scope.row,4)">解除冻结</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagesCon">
      <div>
        <el-pagination
          :current-page="params.pageNum"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="params.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <el-dialog title="请输入解除冻结备注" :visible.sync="dialogVisible" width="20%">
      <el-input v-model="datas.freezeRemark" :rows="2" type="textarea" placeholder="请输入内容" />

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="sure()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import freezingrecord from "@/api/serviceManage/freezingrecord";
export default {
  data() {
    return {
      params: { pageNum: 1, pageSize: 10, realname: "", username: "" },
      tableData: [{ number: 100 }],
      datas: { freezeRemark: "" },
      total: 0,
      //tableLoading
      tableLoading:false,
      dialogVisible: false
    };
  },
  mounted() {
    this.list();
  },
  methods: {
    //确认
    sure() {
      // console.log(this.datas)
      this.changeIsFreezeStatus();
    },
    search() {
      this.params.pageNum = 1;
      this.list();
    },
    //确认函数调用
    changeIsFreezeStatus() {
      freezingrecord.changeIsFreezeStatus(this.datas).then(res => {
        console.log(res);
        if (res.data.code == 0) {
          this.dialogVisible = false;
          this.$message({
            message: res.data.msg,
            type: "success"
          });
          this.list();
        } else {
          this.$message({
            message: res.data.msg,
            type: "warning"
          });
        }
      });
    },
    //列表
    async list() {
      this.tableLoading=true
      let res = await freezingrecord.list(this.params);
      console.log(res)
      if (res.data.code == 0) {
        this.tableData = res.data.data.list;
        this.total = res.data.data.count;
        this.tableLoading=false
      } else {
        this.$message({
          message: res.data.msg,
          type: "warning"
        });
      }
    },
    table_index(index) {
      return (this.params.pageNum - 1) * this.params.pageSize + index + 1;
    },
    handleSizeChange(val) {
      this.params.pageNum = 1;
      this.params.pageSize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.list();
    },
    //解除冻结弹窗参数
    jumufn(data) {
      // console.log(data)
      this.datas.id = data.id;
      this.datas.userId = data.userId;
      this.datas.freeze = data.freeze == 1 ? 2 : 1;
      this.dialogVisible = true;
      // this.$confirm("是否确定解除冻结？", "提示", {
      //   confirmButtonText: "确定",
      //   cancelButtonText: "取消",
      //   callback: action => {
      //     if (action == "confirm") {
      //     }
      //   }
      // });
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
</style>